//刷新
function CollageRefresh() {
    //获取高校配置
    var setting = {
        id: 'collageId',
        code: 'collageId',
        url: ctx + 'collage/getCollageList',
        expandAll: true,
        expandColumn: "2",
        ajaxParams:{
            "collageName":$("#co_name").val()
        },
        columns: [{
            field: 'selectItem',
            checkbox: true
        },
            {
                title: '高校代码',
                field: 'collageCode',
                width: '100px'
            },
            {
                title: '高校/专业名称',
                field: 'collageName'
            },
            {
                title: '类型',
                field: 'collageEdu'
            },
            {
                title: '民办/公办',
                field: 'collageType'
            }
        ]
    };
    $JuXue.initTreeTable1('collageTable', setting);
}

/**
 * 搜索
 * **/
function collageSearch() {
    CollageRefresh();
}

/**
 * 导出
 * **/
function exportCollageExcel() {
    $.post(ctx + "collage/excel", {"collageName":$("#co_name").val()}, function (r) {
        if (r.code === 0) {
            window.location.href = "file/download?fileName=" + r.msg + "&delete=" + true;
        } else {
            $JuXue.n_warning(r.msg);
        }
    });
}

/**
 * 新增高校
 * **/
function addCollage() {
    $.post(ctx+"collage/addDialog",{},function (r) {$("#sale-modal").empty().append(r).modal("show").draggable();});
}

/**
 * 修改高校
 * **/
function editCollage(){
    var selected = $("#collageTable").bootstrapTreeTable("getSelections");
    var selected_length = selected.length;
    if (!selected_length) {$JuXue.n_warning('请勾选需要修改的高校或专业！');return;}
    if (selected_length > 1) {$JuXue.n_warning('一次只能修改一个高校或专业！');return;}
    $.post(ctx+"collage/updateDialog",{},function (r) {$("#sale-modal").empty().append(r).modal("show").draggable();});
}

/**
 * 删除**/
function deleteCollage() {
    var ids = $("#collageTable").bootstrapTreeTable("getSelections");
    var ids_arr = "";
    if (!ids.length) {$JuXue.n_warning("请勾选需要删除的高校或学院！");return;}
    for (var i = 0; i < ids.length; i++) {
        ids_arr += ids[i].id;
        if (i !== (ids.length - 1)) ids_arr += ",";
    }
    $JuXue.confirm({
        text: "确定删除选中高校或学院？",
        confirmButtonText: "确定删除"
    }, function () {
        $.post(ctx + 'collage/delete', {"ids": ids_arr}, function (r) {
            if (r.code === 0) {
                $JuXue.n_success(r.msg);
                CollageRefresh();
            } else {
                $JuXue.n_danger(r.msg);
            }
        });
    });
}